package org.zxp.algorithm.sort.utils;

import java.util.Random;

/**
 * @program: algorithm
 * @description: ${description}
 * @author: X-Pacific zhang
 * @create: 2019-04-07 11:10
 **/
public class Tools {
    public static int[] change(int[] array,int s1,int s2) throws Exception {
        if(s1 < array.length && s2 < array.length){
            int tmp = array[s2];
            array[s2] = array[s1];
            array[s1] = tmp;
        }else{
            throw new Exception("Tools.change 数组越界["+s1+","+s2+"]");
        }
        return array;
    }


    public static void print(int[] sorts){
        for (int i = 0; i < sorts.length; i++) {
            System.out.print(sorts[i]);
        }
        System.out.println();
    }

    public static void check(int[] a) throws Exception {
        int current = a[0];
        for(int i = 1;i < a.length ;i++){
            if(current > a[i]){
                throw new Exception("current:"+current + "  next:"+a[i]);
            }
        }
        System.out.println("通过check");
    }
    public static void printResult(int[] sorts,long time1,long time2,long time3,String type) throws Exception {
        System.out.println("排序元素个数："+sorts.length);
        System.out.println("gen 耗时："+(time2-time1) + "ms");
        System.out.println(type+"排序 耗时："+(time3-time2) + "ms");
        check(sorts);
    }


    public static int[] gen(int n){
        int[] sorts = new int[n];
        for(int i = 0;i < n;i++){
            int value = new Random().nextInt(n);
            sorts[i] = value;
        }
        return sorts;
    }


    public static void main(String[] args) throws Exception {
        int[] a = {4,3,2,1};
        check(a);
    }

}
